<?php

namespace app\api\controller\v1;

use app\api\service\AppToken;
use app\api\validate\AppTokenGet;
use app\api\validate\TokenGet;
use app\api\service\UserToken;
use app\lib\exception\ParameterExcption;
use app\api\service\Token as TokenService;

class Token
{
    public function getToken($code='')
    {
        (new TokenGet())->goCheck();
        $wx = new UserToken($code);
        $token = $wx->get();
        return [
            'token' => $token
        ];
    }

    public function getAppToken($ac='', $se=''){
        (new AppTokenGet())->goCheck();
        $app = new AppToken();
        $token = $app->get($ac, $se);
        return [
            'token'=>$token
        ];
    }

    public function verifyToken($token = ''){
        if(!$token){
            throw  new ParameterExcption(
                [
                   'token不允许为空',
                ]);
        }
        $vaild = TokenService::verifyToken($token);
        return [
            'isValid'=>$vaild,
        ];
    }
}
